package com.ts.tscloud.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @ClassName SwaggerConfig
 * @Author ZXT
 * @Data 2019/12/21 16:10
 **/

@EnableSwagger2
@Configuration
public class SwaggerConfig {


    @Bean
    public Docket zxtDocket(Environment environment){
        //判断是否为开发环境
        Profiles profiles = Profiles.of("dev","test");
        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(zxtApiInfo())
                .groupName("zxt")
                .enable(flag);
    }

    //配置zxt信息
    private ApiInfo zxtApiInfo(){
        Contact zxt = new Contact("zxt", "", "894921757@qq.com");
        return  new ApiInfo(
                "zxt的SwaggerAPI文档",
                "",
                "V1.0",
                "",
                zxt,
                "",
                "",
                new ArrayList()
        );
    }

    @Bean
    public Docket lsDocket(Environment environment){
        Profiles profiles = Profiles.of("dev", "test");
        boolean flag = environment.acceptsProfiles(profiles);

        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(lsApiInfo())
                .enable(flag)
                .groupName("ls");

    }

    private  ApiInfo lsApiInfo(){
        Contact ls = new Contact("ls", "", "");
        return new ApiInfo(
                "ls的SwaggerApi文档",
                "",
                "",
                "",
                ls,
                "",
                "",
                new ArrayList()
        );
    }

}
